package cn.good.yan.controller;


import cn.good.yan.feign.PaymentHystrixService;
import com.netflix.hystrix.contrib.javanica.annotation.DefaultProperties;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 演示 - 客户端
 * 1. Hystrix  服务降级
 *             客户端 - 调用服务端，出现卡死、服务端宕机、自己服务端出故障  - 需要服务降级
 *             DefaultProperties 全局的服务降级配置 ，都走paymentGlobalFallbackMethod方法
 * @author shengren.yan
 * @create 2023-09-20
 */
@Slf4j
@RestController
@RequestMapping("/k1")
@DefaultProperties(defaultFallback = "paymentGlobalFallbackMethod")
public class OrderController2 {

    // Feign 接口
    @Resource
    private PaymentHystrixService paymentHystrixService;

    @HystrixCommand //加了@DefaultProperties属性注解，并且没有写具体方法名字，就用统一全局的
    public String paymentInfoTimeOut(@PathVariable("id") Integer id) {
        String result = paymentHystrixService.paymentInfoTimeOut(id);
        return result;
    }

    /**
     * 全局fallback方法
     *
     * @return
     */
    public String paymentGlobalFallbackMethod() {
        return "Global异常处理信息，请稍后再试，/(ㄒoㄒ)/~~";
    }

}

